<?php
class editor_model extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }
	
	function getAllFile($num,$offset)
	{
		$ar_img = array('gif','png','jpg','jpeg');
		$this->db->where_in('ext',$ar_img);
		$this->db->order_by('img_id','DESC');
		$query = $this->db->get('sys_images',$num,$offset);
		return $query->result();
	}
	
	function getNumFile()
	{
		$query = $this->db->get('sys_images');
		return $query->num_rows();
	} 
  
	function upload()
	{
	  $this->load->library('upload_library');
	  $size = $_FILES["filedata"]["size"];
	  if($size > 0)
	  {
		  $filedata = $this->upload_library->uploadfile();
		  if($filedata!='')
		  {
			  $file = explode('*',$filedata);
			  $url = $file[0];
			  $size = $file[1];
			  $ext = $file[2];
			  $data = array(
				  'lb_name' => $file[3],
				  'lb_url' => $url,
				  'ext' => $ext,
				  'dt_create' => date('Y-m-d H:i:s') 
			  );
			  $this->db->insert('sys_images',$data);
			  return $url;
		  }
	  }else{
		  return '';
	  }
	}       
}
?>
